package com.zjuee.web.auth.service.impl;

import com.zjuee.web.auth.mapper.MenuMapper;
import com.zjuee.service.auth.service.MenuService;
import com.zjuee.service.auth.vo.MenuVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wu liang
 * @since 1.0
 */
@Slf4j
@Service
public class MenuServiceImpl implements MenuService {

    @Resource
    private MenuMapper menuMapper;

    @Override
    public List<MenuVo> findAll() {
        // 获取所有顶层分组
        List<MenuVo> menus = menuMapper.findByParentId(0L);
//        if (menus==null || menus.isEmpty()) {
//            return menus;
//        }
//
//        // 递归循环，填充数据
//        for (MenuVo menu : menus) {
//            setChildren(menu);
//        }
        return menus;
    }

    //获取并设置子分组列表
//    private void setChildren(MenuVo menu) {
//        if (menu==null) {
//            return;
//        }
//        List<MenuVo> childMenus = menuMapper.findByParentId(menu.getId());
//        if (childMenus != null && !childMenus.isEmpty()) {
//            for (MenuVo childMenu : childMenus) {
//                setChildren(childMenu);
//            }
//        }
//        menu.setChildren(childMenus);
//    }
}
